package net.oschina.gitapp.common;

import java.io.File;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory.Options;
import android.graphics.Paint;
import android.os.Build;
import android.provider.MediaStore;
import android.view.View;
import android.view.Window;

/**
 * Android各版本的兼容方法
 * 
 * @author liux (http://my.oschina.net/liux)
 * @version 1.0
 * @created 2012-8-6
 */
public class MethodsCompat {
    
    public static void overridePendingTransition(Activity activity,
            int enter_anim, int exit_anim) {
        activity.overridePendingTransition(enter_anim, exit_anim);
    }
    
    public static Bitmap getThumbnail(ContentResolver cr, long origId,
            int kind, Options options) {
        return MediaStore.Images.Thumbnails.getThumbnail(cr, origId, kind,
                options);
    }
    
    public static File getExternalCacheDir(Context context) {
        
        // // return context.getExternalCacheDir(); API level 8
        //
        // // e.g. "<sdcard>/Android/data/<package_name>/cache/"
        // final File extCacheDir = new
        // File(Environment.getExternalStorageDirectory(),
        // "/Android/data/" + context.getApplicationInfo().packageName +
        // "/cache/");
        // extCacheDir.mkdirs();
        // return extCacheDir;
        
        return context.getExternalCacheDir();
    }
    
    public static void recreate(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            activity.recreate();
        }
    }
    
    public static void setLayerType(View view, int layerType, Paint paint) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            view.setLayerType(layerType, paint);
        }
    }
    
    public static void setUiOptions(Window window, int uiOptions) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            window.setUiOptions(uiOptions);
        }
    }
    
}